﻿package com.tudou.home.newskin.buttons
{
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;

    public class LoadingCircle extends Sprite
    {
        private var rectWidth:int = 3;
        private var rectHeight:int = 12;
        private var timer:Timer;
        private var rectNumber:int = 12;
        private var radius:int = 18;

        public function LoadingCircle()
        {
            createChildren();
            timer = new Timer(50);
            timer.addEventListener(TimerEvent.TIMER, timerHlr);
            timer.start();
            return;
        }// end function

        private function timerHlr(event:TimerEvent) : void
        {
            var _loc_5:int = 0;
            var _loc_6:Sprite = null;
            var _loc_2:* = timer.currentCount % rectNumber;
            var _loc_3:uint = 6;
            var _loc_4:int = 0;
            while (_loc_4 < _loc_3)
            {
                
                _loc_5 = (_loc_2 + _loc_4) % rectNumber;
                _loc_6 = getChildAt(_loc_5) as Sprite;
                _loc_6.getChildAt(0).alpha = (_loc_4 + 1) / _loc_3;
                _loc_4++;
            }
            return;
        }// end function

        private function createChildren() : void
        {
            var _loc_6:Sprite = null;
            var _loc_7:Sprite = null;
            var _loc_1:* = 2 * Math.PI / rectNumber;
            var _loc_2:* = 360 / rectNumber;
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:uint = 0;
            while (_loc_5 < rectNumber)
            {
                
                _loc_6 = new Sprite();
                _loc_6.graphics.beginFill(16777215, 0.1);
                _loc_6.graphics.drawRoundRect((-rectWidth) / 2, (-rectHeight) / 2, rectWidth, rectHeight, 3, 3);
                _loc_6.graphics.endFill();
                _loc_7 = new Sprite();
                _loc_7.graphics.beginFill(16777215, 1);
                _loc_7.graphics.drawRoundRect((-rectWidth) / 2, (-rectHeight) / 2, rectWidth, rectHeight, 3, 3);
                _loc_7.graphics.endFill();
                _loc_7.alpha = 0;
                _loc_6.addChild(_loc_7);
                _loc_6.x = Math.cos(_loc_1 * _loc_5) * radius + _loc_3;
                _loc_6.y = Math.sin(_loc_1 * _loc_5) * radius + _loc_4;
                _loc_6.rotation = _loc_2 * _loc_5 + 90;
                addChild(_loc_6);
                _loc_5 = _loc_5 + 1;
            }
            return;
        }// end function

        override public function set visible(param1:Boolean) : void
        {
            if (param1)
            {
                timer.reset();
                timer.start();
            }
            else
            {
                timer.stop();
            }
            super.visible = param1;
            return;
        }// end function

    }
}
